123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- "use client";
- import { getFindPwdApi } from "@/api/user";
- import ButtonOwn from "@/components/ButtonOwn";
- import DomainFooter from "@/components/DomainFooter";
- import HeaderBack from "@/components/HeaderBack";
- import { useLogout } from "@/hooks/useLogout";
- import { Form, Input, Toast } from "antd-mobile";
- import { FormInstance } from "antd-mobile/es/components/form";
- import clsx from "clsx";
- import { useTranslations } from "next-intl";
- import { useSearchParams } from "next/navigation";
- import { FC, useRef, useState } from "react";
- import { Simulate } from "react-dom/test-utils";
- import "./page.scss";
- import change = Simulate.change;
- interface Props {}
- const ResetPhone: FC<Props> = () => {
- const t = useTranslations();
- const { logout } = useLogout();
- let searchParams = useSearchParams();
- let user_phone = searchParams.get("userPhone");
- let code = searchParams.get("code");
- const findPwdRequest = ({ pwd }: { pwd: string }) => {
- getFindPwdApi({ user_phone, code, pwd })
- .then(async (res) => {
- if (res.code == 200) {
- Toast.show({ icon: "success", content: t("code.200"), maskClickable: false });
- await logout();
- }
- })
- .catch((error) => {
- Toast.show(t(`code.${error.data.code}`));
- });
- };
- /**
- * @description
- */
- const [visible, setVisible] = useState(false);
- const spanClassName = clsx("iconfont", {
- "icon-kejian": visible,
- "icon-bukejian": !visible,
- });
- const formRef = useRef<FormInstance>(null);
- const onFinish = (values: { pwd: string; checkPwd: string }) => {
- findPwdRequest(values);
- };
- const onValuesChange = (changeValue: { pwd: string }) => {
- if (changeValue.pwd) {
- formRef.current?.setFieldValue("pwd", changeValue.pwd.replace(/[^\w\.\/]/gi, ""));
- }
- };
- const checkValidator = (rules: any, value: string) => {
- const password = formRef.current?.getFieldValue("pwd");
- if (value !== password) {
- return Promise.reject(new Error(t("form.checkPwdReg")));
- }
- return Promise.resolve();
- };
- return (
- <div className="confirmPassword-box">
- <HeaderBack />
- <div className="main custom-form">
- <div className="title">
- <h2>{t("confirmPwdPage.title")}</h2>
- {/* <div>修改密码 {user_phone}</div> */}
- </div>
- <Form
- style={{
- "--border-bottom": "none",
- "--border-top": "none",
- "--border-inner": "none",
- }}
- onFinish={onFinish}
- ref={formRef}
- onValuesChange={onValuesChange}
- footer={<ButtonOwn active>{t("confirmPwdPage.complete")}</ButtonOwn>}
- >
- <Form.Item
- name="pwd"
- label=""
- extra={
- <span
- className={spanClassName}
- onClick={() => setVisible(!visible)}
- ></span>
- }
- rules={[
- { required: true, message: t("form.passwordReg") },
- { min: 6, max: 20, message: t("form.passwordMinReg") },
- ]}
- >
- <Input
- placeholder={t("form.newPwd")}
- maxLength={20}
- type={visible ? "text" : "password"}
- />
- </Form.Item>
- <Form.Item
- name="checkPwd"
- label=""
- rules={[
- {
- min: 6,
- max: 20,
- validator: checkValidator,
- },
- ]}
- >
- <Input placeholder={t("form.checkPwd")} maxLength={20} type={"password"} />
- </Form.Item>
- </Form>
- </div>
- <DomainFooter />
- </div>
- );
- };
- export default ResetPhone;
|